package com.guguskins.back.controller;


import com.guguskins.back.entity.GuWithdrawal;
import com.guguskins.back.entity.vo.PageVo;
import com.guguskins.back.entity.vo.ResultVo;
import com.guguskins.back.service.GuWithdrawalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-08-02
 */
@RestController
@RequestMapping("/withdrawal")
public class GuWithdrawalController {

    @Autowired
    private GuWithdrawalService withdrawalService;

    @GetMapping("/back/page")
    public ResultVo backPage(@RequestParam(value = "p", required = false, defaultValue = "1") int p,
                             @RequestParam(value = "size", required = false, defaultValue = "10") int size,
                             @RequestParam(value = "searchKey", required = false, defaultValue = "") String searchKey) {
        PageVo<GuWithdrawal> pageVo = withdrawalService.backPage(p, size, searchKey);
        return ResultVo.success(pageVo);
    }

    @PostMapping("/back/cancel")
    public ResultVo backCancel(@RequestBody GuWithdrawal withdrawal) {
        if (withdrawalService.backCancel(withdrawal)) {
            return ResultVo.success("取消交易成功");
        }
        return ResultVo.fail("取消交易失败");
    }
}
